package com.irononetech.android.MultilevelListView;

import android.app.ExpandableListActivity;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.irononetech.android.Application.Application;
import com.irononetech.android.formcomponent.FormObject;
import com.irononetech.android.formcomponent.view.VehicleDetailsActivity;
import com.irononetech.android.claimsonersa.R;

public class ExpList3_Bus extends ExpandableListActivity
{
	Logger LOG = LoggerFactory.getLogger(ExpList3_Bus.class);


	static final String listdesc[][][][] = 
		{
		{ // grey
			{  // lightgray
				{ "Bus", "Front face panel" },
				{ "Front buffer","" },
				{ "Front windscreen","" },
				{ "Front grill","" },
				{ "Front badge","" },
				{ "Dash board","" },
				{ "A/C blower","" },
				{ "A/C cooler","" },
				{ "R/H/S front windscreen","" },
				{ "L/H/S front windscreen","" },
				{ "R/H/S front windscreen beading","" },
				{ "L/H/S front windscreen beading","" },
				{ "Front windscreen (single glass)","" },
				{ "Front single windscreen beading","" },
				{ "L/H/S front buffer end ","" },
				{ "R/H/S front buffer end","" },
				{ "Front face aluminum molding","" },
				{ "R/H/S head lamp","" },
				{ "L/H/S head lamp","" },
				{ "R/H/S head lamp frame","" },
				{ "L/H/S head lamp frame","" },
				{ "R/H/S front signal lamp","" },
				{ "L/H/S front signal lamp","" },
				{ "R/H/S front parking lamp","" },
				{ "L/H/S front parking lamp","" },
				{ "Front name board glass","" },
				{ "Front name board light","" },
				{ "Front name board glass beading","" },
				{ "A/C Condenser","" },
				{ "A/C Filter","" },
				{ "Horn","" },
				{ "Air horn","" },
				{ "Front number plate","" },
				{ "Front number plate lamp","" }
			},
			{  // darkgray
				{ "Bus", "Right body panel" },
				{ "R/H/S driver door","" },
				{ "R/H/S cut glass","" },
				{ "R/H/S fit glass","" },
				{ "R/H/S rain gutter","" },
				{ "R/H/S body molding","" },
				{ "R/H/S door hinges","" },
				{ "R/H/S front tire","" },
				{ "R/H/S Driver door glass","" },
				{ "R/H/S Driver door glass beading","" },
				{ "R/H/S Door hinges","" },
				{ "R/H/S Cut glass frames","" },
				{ "R/H/S Fit glass frames","" },
				{ "R/H/S Cut glass beading","" },
				{ "R/H/S Fit glass beading","" },
				{ "R/H/S Body aluminum molding","" },
				{ "R/H/S Emergency door","" },
				{ "R/H/S Emergency door glass","" },
				{ "R/H/S Emergency door glass beading","" },
				{ "R/H/S Front rim","" },
				{ "R/H/S Rear tire outer","" },
				{ "R/H/S Rear tire outer rim","" },
				{ "R/H/S Rear tire inner","" },
				{ "R/H/S Rear tire inner rim","" },
				{ "R/H/S Mirror","" },
				{ "R/H/S Front tire Wheel nuts","" },
				{ "R/H/S Rear tire outer Wheel nuts","" },
				{ "R/H/S Rear tire inner Wheel nuts","" },
				{ "Rim cups (if available)","" },
				{ "Side lights","" },
				{ "Body beading aluminum","" },
				{ "Body beading rubber","" }
			},
			{  // darkgray
				{ "Bus", "Left body panel" },
				{ "L/H/S front door","" },
				{ "L/H/S front board","" },
				{ "L/H/S cut glasses","" },
				{ "L/H/S foot board","" },
				{ "L/H/S fit glasses","" },
				{ "L/H/S body rubber","" },
				{ "L/H/S rear tire inner","" },
				{ "L/H/S Front door glass","" },
				{ "L/H/S Front door glass beading","" },
				{ "L/H/S Front door rubber flap","" },
				{ "L/H/S Front door winder","" },
				{ "L/H/S Foot board lamp","" },
				{ "L/H/S Front rain gutter","" },
				{ "L/H/S Body aluminum molding","" },
				{ "L/H/S Body rubber molding","" },
				{ "L/H/S Cut glasses frames","" },
				{ "L/H/S Fit glasses frames","" },
				{ "L/H/S Cut glass beading","" },
				{ "L/H/S Fit glasses beading","" },
				{ "L/H/S Rear foot board","" },
				{ "L/H/S Rear foot board lamp","" },
				{ "L/H/S Rear foot board door","" },
				{ "L/H/S Rear foot board door glass","" },
				{ "L/H/S Rear foot board door beading","" },
				{ "L/H/S Rear foot board door rubber flap","" },
				{ "L/H/S Rear rain gutter","" },
				{ "L/H/S Front tire","" },
				{ "L/H/S Front tire rim","" },
				{ "L/H/S Rear tire outer","" },
				{ "L/H/S Rear tire outer rim","" },
				{ "L/H/S Rear tire inner","" },
				{ "L/H/S Rear tire inner rim","" },
				{ "L/H/S Front tire Wheel nuts","" },
				{ "L/H/S Rear tire outer Wheel nuts","" },
				{ "L/H/S Rear tire inner Wheel nuts","" },
				{ "L/H/S Rim cups (if available)","" },
				{ "Side lights","" },
				{ "Body beading aluminum","" }, 
				{ "Body beading rubber","" }
			},
			{  // darkgray
				{ "Bus", "Rear side" },
				{ "Rear buffer","" },
				{ "Dickey door","" },
				{ "Dickey door lights","" },
				{ "Dickey door ladder","" },
				{ "Rear number plate","" },
				{ "Dickey door locks","" },
				{ "Dickey door garnish","" },
				{ "Dickey door handles","" },
				{ "Dickey door beadings","" },
				{ "Rear windscreen","" },
				{ "R/H/S Rear windscreen","" },
				{ "L/H/S Rear windscreen","" },
				{ "R/H/S Rear windscreen beading","" },
				{ "R/H/S Rear windscreen beading","" }, 
				{ "Rear windscreen beading","" },
				{ "Rear name board box glass","" },
				{ "Rear name board box glass beading","" },
				{ "Rear name board box glass lamp","" },
				{ "L/H/S tail light rear","" },
				{ "R/H/S Rear tail light","" },
				{ "L/H/S Rear tail light","" },
				{ "R/H/S rear parking lamp","" },
				{ "L/H/S rear parking lamp","" },
				{ "R/H/S rear buffer end","" },
				{ "L/H/S rear buffer end","" },
				{ "Rear number plate lamp","" },
				{ "Back body aluminum molding","" }, 
				{ "Back body rubber beading","" },
				{ "Rear windscreen mirror","" },
				{ "Body beading rubber","" },
				{ "Body beading aluminum","" }
			},
			{
				{ "Bus", "Engine compartment and components" },
				{ "Diesel, petrol engine (gasoline engine)","" },
				{ "Accessory belt","" },
				{ "Air duct","" },
				{ "Air intake housing","" },
				{ "Air intake manifold","" },
				{ "Camshaft","" },
				{ "Camshaft bearing","" },
				{ "Camshaft fastener","" },
				{ "Camshaft follower","" },
				{ "Camshaft locking plate","" },
				{ "Camshaft pushrod","" },
				{ "Camshaft spacer ring","" },
				{ "Connecting rod","" },
				{ "Connecting rod bearing","" },
				{ "Connecting rod bolt","" },
				{ "Connecting rod washer","" },
				{ "Crank case","" },
				{ "Crank pulley","" },
				{ "Crankshaft","" },
				{ "Crankshaft oil seal","" },
				{ "Cylinder head","" },
				{ "Cylinder head cover","" },
				{ "Other cylinder head cover parts","" },
				{ "Cylinder head gasket","" },
				{ "Distributor","" },
				{ "Distributor cap","" }, 
				{ "Drive belt","" },
				{ "Engine block","" }, 
				{ "Engine block parts","" },
				{ "Engine cradle","" },
				{ "Engine shake damper and vibration absorber","" },
				{ "Engine valve","" },
				{ "Fan belt","" },
				{ "Gudgeon pin (wrist pin)","" },
				{ "Harmonic balancer","" },
				{ "Heater","" },
				{ "Mounting bolt","" },
				{ "Piston pin and crank pin","" },
				{ "Piston pin bush","" },
				{ "Piston ring and circlip","" },
				{ "Piston valve","" }, 
				{ "Poppet valve","" }, 
				{ "PCV valve (positive crankcase ventilation valve)","" },  
				{ "Pulley part","" }, 
				{ "Rocker arm","" }, 
				{ "Rocker cover Starter motor","" }, 
				{ "Rocker cover Starter pinion","" }, 
				{ "Rocker cover Starter ring","" }, 
				{ "Turbocharger and supercharger","" },  
				{ "Tappet","" },
				{ "Timing tape ","" }, 
				{ "Valve cover","" },
				{ "Valve housing","" }, 
				{ "Valve spring","" },
				{ "Valve stem seal","" }, 
				{ "Water pump pulley","" }
			},
			{
				{ "Bus", "Engine cooling system" },
				{ "Air blower","" },
				{ "Coolant hose cooling fan","" }, 
				{ "Fan blade","" },
				{ "Fan clutch","" },
				{ "Radiator bolt","" },
				{ "Radiator shroud","" },
				{ "Radiator gasket","" },
				{ "Radiator pressure cap","" }, 
				{ "Water neck","" },
				{ "Water neck o-ring","" }, 
				{ "Water pipe","" },
				{ "Water pump","" },
				{ "Water pump gasket","" }, 
				{ "Water tank","" },
				{ "Thermostat","" }
			},
			{          
				{ "Bus", "Engine oil system" },
				{ "Oil filter","" }, 
				{ "Oil gasket","" }, 
				{ "Oil pan","" },
				{ "Oil pipe","" }, 
				{ "Oil pump","" }, 
				{ "Oil strainer","" }
			},
			{
				{ "Bus","Exhaust system" },
				{ "Catalytic converter","" },
				{ "Exhaust clamp and bracket","" }, 
				{ "Exhaust flange gasket","" },
				{ "Exhaust gasket","" }, 
				{ "Exhaust manifold","" }, 
				{ "Exhaust manifold gasket","" }, 
				{ "Exhaust pipe","" }, 
				{ "Heat shield","" }, 
				{ "Heat sleeving and tape","" }, 
				{ "Muffler (silencer)","" }
			},
			{
				{ "Bus", "Fuel supply system" },
				{ "Air filter","" },
				{ "Carburetor","" },
				{ "Carburetor parts","" },
				{ "Choke cable","" },
				{ "EGR valve","" },
				{ "Fuel cap","" },
				{ "Fuel cell","" },
				{ "Fuel cell component","" },
				{ "Fuel cooler","" },
				{ "Fuel distributor","" },
				{ "Fuel filter","" },
				{ "Fuel filter seal","" },
				{ "Fuel injector","" },
				{ "Fuel injector nozzle","" },
				{ "Fuel pump","" },
				{ "Fuel pump gasket","" },
				{ "Fuel pressure regulator","" },
				{ "Fuel rail","" },
				{ "Fuel tank","" },
				{ "Fuel tank cover","" },
				{ "Fuel water separator","" },
				{ "Intake manifold","" },
				{ "Intake manifold gasket","" },
				{ "LPG (Liquefied petroleum gas) system assembly","" }, 
				{ "Throttle body","" },
				{ "Universal joint","" }
			},
			{
				{ "Bus","Other miscellaneous parts" },
				{ "Adhesive tape and foil","" },  
				{ "Bolt cap","" },
				{ "License plate bracket","" }, 
				{ "Speedometer cable","" },
				{ "Cotter pin","" }, 
				{ "Decal","" }, 
				{ "Dashboard","" }, 
				{ "Center console","" }, 
				{ "Glove compartment","" }, 
				{ "Drag link","" }, 
				{ "Dynamic seal","" }, 
				{ "Fastener","" }, 
				{ "Gasket: Flat, molded, profiled","" }, 
				{ "Hood and trunk release cable","" }, 
				{ "Horn and trumpet horn","" }, 
				{ "Injection-molded parts","" }, 
				{ "Instrument cluster","" }, 
				{ "Label","" }, 
				{ "Mirror","" }, 
				{ "Mount and mounting","" }, 
				{ "Name plate","" }, 
				{ "Flange nut","" }, 
				{ "Hex nut","" }, 
				{ "O-ring","" }, 
				{ "Paint","" },
				{ "Rivet","" },
				{ "Rubber (extruded and molded)","" }, 
				{ "Screw","" }, 
				{ "Shim","" },
				{ "Sun visor","" }
			},
		}
		};

	FormObject fo;
	static boolean booleanlistBus[][][][];
	static boolean booleanprelistBus[][][][];
	Button back;
	EditText otherfield;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle icicle)
	{
		try {
			super.onCreate(icicle);
			LOG.debug("ENTRY onCreate");
			setContentView(R.layout.multilevel_expandable_list_main);
			fo = Application.getFormObjectInstance();
			back = (Button)findViewById(R.id.button2);
			otherfield = (EditText)findViewById(R.id.damagedItemsOtherField);

			if(fo.getisPreSelected())  //PRE
			{
				otherfield.setText(fo.getpredamagedItemsOtherField());
				booleanprelistBus = fo.getBooleanprelistBus();
				colorExpListAdapter=
						new ColorExpListAdapterBus(this, getExpandableListView(), listdesc);
				setListAdapter( colorExpListAdapter );

				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			}
			else {
				otherfield.setText(fo.getdamagedItemsOtherField());
				booleanlistBus = fo.getBooleanlistBus();
				colorExpListAdapter = new ColorExpListAdapterBus(this, getExpandableListView(), listdesc);
				setListAdapter( colorExpListAdapter );

				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.cancel_button_xml));
			}
			if(!fo.isEditable()){
				editDisable();
			}
			LOG.debug("SUCCESS onCreate");
		} catch (NotFoundException e) {
			LOG.error("onCreate:10295");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			LOG.error("onCreate:10296");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	public void editDisable() {
		try {
			otherfield.setFocusable(false);

			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			}
		} catch (NotFoundException e) {
			LOG.error("editDisable:10297");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			LOG.error("editDisable:10298");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	public void editEnable() {
		try {
			otherfield.setFocusable(true);

			if(fo.getisPreSelected())  //PRE
			{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_button_xml));
			} else{
				back.setBackgroundDrawable(getResources().getDrawable(R.drawable.cancel_button_xml));
			}
		} catch (NotFoundException e) {
			LOG.error("editEnable:10299");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		} catch (Exception e) {
			LOG.error("editEnable:10300");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}


	public void multilevel_ok_click(View v){
		try {
			if(fo.getisPreSelected())  //PRE
			{
				fo.setBooleanprelistBus(booleanprelistBus);
				fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
			}
			else {
				fo.setBooleanlistBus(booleanlistBus);
				fo.setdamagedItemsOtherField(otherfield.getText().toString().trim());
			}

			Intent mIntent = new Intent(ExpList3_Bus.this, VehicleDetailsActivity.class);
			mIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(mIntent);
			finish();
		} catch (Exception e) {
			LOG.error("editEnable:10301");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}


	public void multilevel_back_button(View v){
		try {
			if (fo.isEditable()) {
				int p1 = Application.get4DArrSizeSec1();
				int p2 = Application.get4DArrSizeSec2();
				int p3 = Application.get4DArrSizeSec3();
				int p4 = Application.get4DArrSizeSec4();
				boolean[][][][] a = new boolean[p1][p2][p3][p4];
				if(!fo.getisPreSelected()) {
					//Damaged Items
					fo.setisVehicleShow(true);
					fo.setdamagedItemsOtherField("");
					fo.setpredamagedItemsOtherField("");
					fo.setBooleanlistBus(a);
					fo.setBooleanprelistBus(a);
				}
				else{
					//Pre Damaged Items
					fo.setBooleanprelistBus(a);
					fo.setpredamagedItemsOtherField(otherfield.getText().toString().trim());
				}
			}
			finish();
		} catch (Exception e) {
			LOG.error("editEnable:10302");
			   if(e != null){
				LOG.error("Message: " + e.getMessage());
				LOG.error("StackTrace: " + e.getStackTrace());
			  }
		}
	}

	private ColorExpListAdapterBus colorExpListAdapter;
}
